package com.koala.learn.minio;

import io.minio.MinioClient;
import io.minio.PutObjectOptions;
import io.minio.errors.*;
import lombok.SneakyThrows;

import java.io.File;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;


/**
 * minio 学习
 *
 * @author yantingrui
 * @date 2022/9/7   11:01
 */
public class Start {

    //你的endpoint,本机可以不变,注意前面http://不能省略
    private final static String endpoint = "http://10.199.117.152:9000";
    //你的accessKey,就是上面图片里的accessKey
    private final static String accessKey = "ERr1SVAdTyCbnG4F";
    //你的sercetKey,上面图片里的sercetKey
    private final static String secretKey = "EToRInGOa00mmqJZKwMxzFKRGnhOp2k7";

    @SneakyThrows
    public static void main(String[] args) {
        uploadFile();
    }

    private static void uploadFile() throws InvalidPortException, InvalidEndpointException, IOException, InvalidKeyException, InvalidResponseException, InsufficientDataException, NoSuchAlgorithmException, InternalException, XmlParserException, InvalidBucketNameException, ErrorResponseException {
        MinioClient minioClient = new MinioClient(endpoint, accessKey, secretKey);
        //boolean test = minioClient.bucketExists("test");
        File file = new File("D://1.webp");
        PutObjectOptions options = new PutObjectOptions(file.length(), -1);
        options.setContentType("image/webp");
        minioClient.putObject("test", "test.webp", "D://1.webp", options);
    }
}
